﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using cocos2d;
using CampaignWP7.Base;
using Microsoft.Xna.Framework;

namespace CampaignWP7
{
    //this emitter is weapon!! bing!!
    public class BulletEmitter : DynamicsEmitter
    {
        public float EmitTime { get; set; }
        public float Strength { get; set; }
        public enum EmitType { ET_Single = 0, ET_Treble }
        public EmitType EType { set; get; }
        public BulletEmitter()
        {
            Reset();
            Enable = false;
           
        }
        public override void Emit(float dt)
        {
            if (!Enable) return;
            Counter += dt;
            EmitTime += dt;
            if (Counter > DelayTime)
            {
                Counter = 0;
                //
                if (EType == EmitType.ET_Single)
                {
                    Bullet bullet = new Bullet();
                    bullet.position = new CCPoint(position.x, position.y);
                    bullet.PlayShootAnimation();
                    bullet.Velocity = Direction * Strength;
                    //
                    DynamicMgr.Instance().AddChild(bullet);
                }
                else if (EType == EmitType.ET_Treble)
                {
                    Bullet bullet_1 = new Bullet();
                    bullet_1.position = new CCPoint(position.x, position.y);
                    bullet_1.PlayShootAnimation();
                    bullet_1.Velocity = new Vector2(0.7071f, 0.7071f) * Strength;
                    bullet_1.RotationEnable = true;
                    //bullet.Acceleration
                    Bullet bullet_2 = new Bullet();
                    bullet_2.position = new CCPoint(position.x, position.y);
                    bullet_2.PlayShootAnimation();
                    bullet_2.Velocity = Direction * Strength;
                    //
                    Bullet bullet_3 = new Bullet();
                    bullet_3.position = new CCPoint(position.x, position.y);
                    bullet_3.PlayShootAnimation();
                    bullet_3.Velocity = new Vector2(0.7071f, -0.7071f) * Strength;
                    bullet_3.RotationEnable = true;

                    //
                    DynamicMgr.Instance().AddChild(bullet_1);
                    DynamicMgr.Instance().AddChild(bullet_2);
                    DynamicMgr.Instance().AddChild(bullet_3);
                }

            }

        }
        //
        public override void Reset()
        {
            //
            DelayTime = 0.5f;
            Strength = 13;
            Direction = new Vector2(1, 0);
            EType = EmitType.ET_Single;
            //
            Counter = 0;
            EmitTime = 0;
            //
        }
        //
        public bool CanEmit(float dt)
        {
            return (Counter + dt > DelayTime);
        }
    }

     
}
